package cn.bugstack.springframework.beans.factory.support;

import cn.bugstack.springframework.beans.BeansException;
import cn.bugstack.springframework.beans.factory.config.BeanDefinition;

/**
 * <p>实现默认bean创建的抽象bean工厂超类
 *
 * @author Yaxi.Zhang
 * @since 2022/12/12 10:41
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {

    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeansException {
        Object bean;
        try {
            System.out.println("get bean from bean class create!");
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed", e);
        }
        // 创建bean过程中，将bean缓存起来供后续流程调用！
        registerSingleton(beanName, bean);
        return bean;
    }

}
